// pages/forensics/pages/v/index.js
var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        is_notary:0,
        currentTab: 0, //默认选项
        order_status: 0,
        scroll_Top: 0,
        appear: false, //是否卡位
        info_list: [ //数据
            
        ],
        no_list: false, //是否有数据
        pageIndex: 1,
        loadding: false,
        pullUpOn: true,
    },
        //tab 切换
        change_tab: function (e) {
            // 0 进行中 1已完成
            let order_status = e.currentTarget.dataset.order_status; //当前选中的
            this.data.order_status = order_status
            let currentTab = this.data.currentTab;
            if (currentTab == order_status) { //防止重复点击
                return false;
            }
            wx.showLoading({
                title: '加载中',
                mask: true
            })
            this.setData({
                currentTab: order_status
            })
            app.globalData.currentTab = order_status;
            //插入数据后记得隐藏（延迟为了查看效果，以实际插入完成后隐藏）
            setTimeout(function () {
                wx.hideLoading()
            }, 1500)
            let params = {}
            params.order_status = order_status;
            params.is_notary = this.data.is_notary;
            getApp()._post_form('data/api.login/getnotaryorder', params, (result) => {
                this.setData({
                    info_list: result.data.list,
                });
            })
        },
        //跳转详情
        // to_detail: function (e) {
        //     let order_no = e.currentTarget.dataset.order_no;
        //     wx.navigateTo({
        //         url: '/pages/order_related/pages/detail/index?order_no=' + order_no,
        //     })
        // },
            //页面滚动
    onPageScroll(e) {
        var scrollTop = e.scrollTop;
        if (scrollTop > this.data.scroll_Top) {
            this.setData({
                appear: true
            })
            return false;
        } else {
            this.setData({
                appear: false
            })
        }
    },
    //获取tab距顶部距离
    get_tab: function () {
        var that = this;
        wx.createSelectorQuery().select('.tabs_box').boundingClientRect(
            function (rect) {
                console.log(rect)
                that.setData({
                    scroll_Top: rect.top,
                })
            }
        ).exec()
    },
    //视频取证
    video_forensics: function (e) {
        let index = e.currentTarget.dataset.index
        let id = this.data.info_list[index].id
        wx.navigateTo({
            url: '/pages/forensics/pages/index/index?record_id='+id+'&is_notary='+this.data.is_notary,
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let is_notary = options.is_notary
        this.setData({
            is_notary:is_notary
        })
        this.get_tab();
        
        let params = {}
        params.order_status = 0;
        params.is_notary = this.data.is_notary;
        getApp()._post_form('data/api.login/getnotaryorder', params, (result) => {
            this.setData({
                info_list: result.data.list,
            });
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {
        var that = this;
        // if (!that.data.pullUpOn) return;
        that.setData({
            loadding: true
        }, () => {

            // let params = {}
            // params.page = that.data.pageIndex + 1;
            // getApp()._post_form('data/api.login/getnotaryorder', params, (result) => {
            //     if (result.data.list.length == 0) {
            //         that.setData({
            //             loadding: false,
            //             pullUpOn: false
            //         })
            //     } else {
            //         //解构和concat修改均会失败？？
            //         setTimeout(() => {
            //             that.setData({
            //                 info_list: that.data.info_list.concat(result.data.list),
            //                 pageIndex: that.data.pageIndex + 1,
            //                 loadding: false
            //             })
            //         }, 500)
            //     }
            // })

            let params = {}
            params.order_status = this.data.order_status;
            params.is_notary = this.data.is_notary;
            getApp()._post_form('data/api.login/getnotaryorder', params, (result) => {
                this.setData({
                    info_list: result.data.list,
                });
                that.setData({
                    loadding: false,
                    pullUpOn: false
                })
            })
        })
    },

})